<?php
/* 	These code was generated using phpCIGen v 0.1.b (24/06/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 19 Surabaya, http://www.ts.co.id

	+ Module  		: m_customer View
	+ Description	: For record view
	+ Filename 		: v_m_customer.php
 	+ creator  		: 
 	+ Created on 06/Mar/2012 12:35:49

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/* declare function */
var m_customer_DataStore;
var m_customer_ColumnModel;
var m_customer_ListEditorGrid;
var m_customer_saveForm;
var m_customer_searchForm;
var m_customer_searchWindow;
var m_customer_SelectedRow;
var m_customer_ContextMenu;
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Batal";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Ubah";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Export Excel";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Lanjut Data";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (hmtl)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;

/* declare variable here for Field*/
var customer_idField;
var customer_cpField;
var customer_hpField;
var customer_nameField;
var customer_addressField;
var customer_cityField;
var customer_postField;
var customer_phoneField;
var customer_faxField;
var customer_mailField;
/* For search form */
var customer_idSearchField;
var customer_cpSearchField;
var customer_hpSearchField;
var customer_nameSearchField;
var customer_addressSearchField;
var customer_citySearchField;
var customer_postSearchField;
var customer_phoneSearchField;
var customer_faxSearchField;
var customer_mailSearchField;

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */

  	/* Function for Saving inLine Editing */
	function m_customer_inline_update(oGrid_event){

	var patt=new RegExp("U");
	if(patt.test(PERMISSION)==false){

		Ext.MessageBox.show({
		   title: 'Warning',
		   msg: FAILED_PERMISSION,
		   buttons: Ext.MessageBox.OK,
		   animEl: 'security',
		   icon: Ext.MessageBox.WARNING
		});

	}else{

		var customer_id_update=null;
		var customer_cp_update=null;
		var customer_hp_update=null;
		var customer_name_update=null;
		var customer_address_update=null;
		var customer_city_update=null;
		var customer_post_update=null;
		var customer_phone_update=null;
		var customer_fax_update=null;
		var customer_mail_update=null;

		if(oGrid_event.record.data.customer_id!== null){customer_id_update = oGrid_event.record.data.customer_id;}
		if(oGrid_event.record.data.customer_cp!== null){customer_cp_update = oGrid_event.record.data.customer_cp;}
		if(oGrid_event.record.data.customer_hp!== null){customer_hp_update = oGrid_event.record.data.customer_hp;}
		if(oGrid_event.record.data.customer_name!== null){customer_name_update = oGrid_event.record.data.customer_name;}
		if(oGrid_event.record.data.customer_address!== null){customer_address_update = oGrid_event.record.data.customer_address;}
		if(oGrid_event.record.data.customer_city!== null){customer_city_update = oGrid_event.record.data.customer_city;}
		if(oGrid_event.record.data.customer_post!== null){customer_post_update = oGrid_event.record.data.customer_post;}
		if(oGrid_event.record.data.customer_phone!== null){customer_phone_update = oGrid_event.record.data.customer_phone;}
		if(oGrid_event.record.data.customer_fax!== null){customer_fax_update = oGrid_event.record.data.customer_fax;}
		if(oGrid_event.record.data.customer_mail!== null){customer_mail_update = oGrid_event.record.data.customer_mail;}

		Ext.Ajax.request({
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_m_customer&m=get_action',
			params: {
				customer_id	:customer_id_update,
				customer_cp	:customer_cp_update,
				customer_hp	:customer_hp_update,
				customer_name	:customer_name_update,
				customer_address	:customer_address_update,
				customer_city	:customer_city_update,
				customer_post	:customer_post_update,
				customer_phone	:customer_phone_update,
				customer_fax	:customer_fax_update,
				customer_mail	:customer_mail_update,
				task: "UPDATE"
			},
			success: function(response){
				var result=eval(response.responseText);
				switch(result){
					case 1:
						m_customer_DataStore.commitChanges();
						m_customer_DataStore.reload();
						break;
					default:
						Ext.MessageBox.show({
						   title: 'Warning',
						   msg: FAILED_SAVE,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'save',
						   icon: Ext.MessageBox.WARNING
						});
						break;
				}
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.show({
				   title: 'Error',
				   msg: FAILED_CONNECTION,
				   buttons: Ext.MessageBox.OK,
				   animEl: 'database',
				   icon: Ext.MessageBox.ERROR
				});
			}
		});

		}
	}
  	/* End of Function */

  	/* Function for add and edit data form, open window form */
	function m_customer_save(){

		var patt=new RegExp("U");
		var patt2=new RegExp("C");
		if(patt.test(PERMISSION)==false && patt2.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

		if(is_m_customer_form_valid()){
			var customer_id_field=null;
			var customer_cp_field=null;
			var customer_hp_field=null;
			var customer_name_field=null;
			var customer_address_field=null;
			var customer_city_field=null;
			var customer_post_field=null;
			var customer_phone_field=null;
			var customer_fax_field=null;
			var customer_mail_field=null;

			if(customer_idField.getValue()!== null){customer_id_field = customer_idField.getValue();}
			if(customer_cpField.getValue()!== null){customer_cp_field = customer_cpField.getValue();}
			if(customer_hpField.getValue()!== null){customer_hp_field = customer_hpField.getValue();}
			if(customer_nameField.getValue()!== null){customer_name_field = customer_nameField.getValue();}
			if(customer_addressField.getValue()!== null){customer_address_field = customer_addressField.getValue();}
			if(customer_cityField.getValue()!== null){customer_city_field = customer_cityField.getValue();}
			if(customer_postField.getValue()!== null){customer_post_field = customer_postField.getValue();}
			if(customer_phoneField.getValue()!== null){customer_phone_field = customer_phoneField.getValue();}
			if(customer_faxField.getValue()!== null){customer_fax_field = customer_faxField.getValue();}
			if(customer_mailField.getValue()!== null){customer_mail_field = customer_mailField.getValue();}

			Ext.Ajax.request({
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_m_customer&m=get_action',
				params: {
					customer_id	: customer_id_field,
					customer_cp	: customer_cp_field,
					customer_hp	: customer_hp_field,
					customer_name	: customer_name_field,
					customer_address	: customer_address_field,
					customer_city	: customer_city_field,
					customer_post	: customer_post_field,
					customer_phone	: customer_phone_field,
					customer_fax	: customer_fax_field,
					customer_mail	: customer_mail_field,
					task: post2db
				},
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
							m_customer_DataStore.reload();
							m_customer_reset_form();
							break;
						default:
							Ext.MessageBox.show({
							   title: 'Warning',
							   msg: FAILED_SAVE,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'save',
							   icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					var result=response.responseText;
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: FAILED_CONNECTION,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});
				}
			});

		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_VALID_FORM,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}

		}
	}
 	/* End of Function */

  	/* Function for get PK field */
	function get_pk_id(){
		if(post2db=='UPDATE')
			return m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_id');
		else
			return 0;
	}
	/* End of Function  */

	/* Reset form before loading */
	function m_customer_reset_form(){
		post2db="CREATE";
		customer_idField.reset();
		customer_idField.setValue(null);
		customer_cpField.reset();
		customer_cpField.setValue(null);
		customer_hpField.reset();
		customer_hpField.setValue(null);
		customer_nameField.reset();
		customer_nameField.setValue(null);
		customer_addressField.reset();
		customer_addressField.setValue(null);
		customer_cityField.reset();
		customer_cityField.setValue(null);
		customer_postField.reset();
		customer_postField.setValue(null);
		customer_phoneField.reset();
		customer_phoneField.setValue(null);
		customer_faxField.reset();
		customer_faxField.setValue(null);
		customer_mailField.reset();
		customer_mailField.setValue(null);
	}
 	/* End of Function */

	/* setValue to EDIT */
	function m_customer_set_form(){
		customer_idField.setValue(m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_id'));
		customer_cpField.setValue(m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_cp'));
		customer_hpField.setValue(m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_hp'));
		customer_nameField.setValue(m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_name'));
		customer_addressField.setValue(m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_address'));
		customer_cityField.setValue(m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_city'));
		customer_postField.setValue(m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_post'));
		customer_phoneField.setValue(m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_phone'));
		customer_faxField.setValue(m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_fax'));
		customer_mailField.setValue(m_customer_ListEditorGrid.getSelectionModel().getSelected().get('customer_mail'));
	}
	/* End setValue to EDIT*/

	/* Function for Check if the form is valid */
	function is_m_customer_form_valid(){
		return (true  																																								);
	}
  	/* End of Function */

  	/* Function for Displaying  create Window Form */
	function display_form_window(){
			post2db='CREATE';
			msg='created';
			m_customer_reset_form();
	}
  	/* End of Function */

  	/* Function for Delete Confirm */
	function m_customer_confirm_delete(){
		// only one m_customer is selected here
		if(m_customer_ListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_DELETE, m_customer_delete);
		} else if(m_customer_ListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_MULTI_DELETE, m_customer_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_DELETE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */

	/* Function for Update Confirm */
	function m_customer_confirm_update(){
		/* only one record is selected here */
		if(m_customer_ListEditorGrid.selModel.getCount() == 1) {
			post2db='UPDATE';
			msg='updated';
			m_customer_set_form();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_UPDATE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */

  	/* Function for Delete Record */
	function m_customer_delete(btn){
		if(btn=='yes'){

		var patt=new RegExp("D");
		if(patt.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

			var selections = m_customer_ListEditorGrid.selModel.getSelections();
			var prez = [];
			for(i = 0; i< m_customer_ListEditorGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.customer_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_m_customer&m=get_action',
				params: { task: "DELETE", ids:  encoded_array },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							m_customer_DataStore.reload();
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: FAILED_DELETE,
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					var result=response.responseText;
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});

			}

		}
	}
  	/* End of Function */

	/* Function for Retrieve DataStore */
	m_customer_DataStore = new Ext.data.Store({
		id: 'm_customer_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_m_customer&m=get_action',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'customer_id'
		},[
			{name: 'customer_id', type: 'int', mapping: 'customer_id'},			{name: 'customer_cp', type: 'string', mapping: 'customer_cp'},			{name: 'customer_hp', type: 'string', mapping: 'customer_hp'},			{name: 'customer_name', type: 'string', mapping: 'customer_name'},			{name: 'customer_address', type: 'string', mapping: 'customer_address'},			{name: 'customer_city', type: 'string', mapping: 'customer_city'},			{name: 'customer_post', type: 'string', mapping: 'customer_post'},			{name: 'customer_phone', type: 'string', mapping: 'customer_phone'},			{name: 'customer_fax', type: 'string', mapping: 'customer_fax'},			{name: 'customer_mail', type: 'string', mapping: 'customer_mail'}		]),
		sortInfo:{field: 'customer_id', direction: "DESC"}
	});
	/* End of Function */

  	/* Function for Identify of Window Column Model */
	m_customer_ColumnModel = new Ext.grid.ColumnModel(
		[
		{
			header: 'Customer Id',
			dataIndex: 'customer_id',
			width: 150,
			sortable: true,
                        hidden: true,
			editor: new Ext.form.NumberField({
				allowDecimals: false,
					allowNegative: false,
				blankText: '0',
				maxLength: 11,
				maskRe: /([0-9]+)$/
			})
		},
		{
			header: 'Kontak',
			dataIndex: 'customer_cp',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		},
		{
			header: 'No HP',
			dataIndex: 'customer_hp',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		},
		{
			header: 'Perusahaan',
			dataIndex: 'customer_name',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		},
		{
			header: 'Alamat',
			dataIndex: 'customer_address',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		},
		{
			header: 'Kota',
			dataIndex: 'customer_city',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		},
		{
			header: 'Kode Pos',
			dataIndex: 'customer_post',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		},
		{
			header: 'Telpon',
			dataIndex: 'customer_phone',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		},
		{
			header: 'Fax',
			dataIndex: 'customer_fax',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		},
		{
			header: 'eMail',
			dataIndex: 'customer_mail',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		}	]);

	m_customer_ColumnModel.defaultSortable= true;
	/* End of Function */

    /* Button Control */
    m_customer_gbtn_add=new Ext.Button({
	    text: BTN_ADD_TITLE,
		tooltip: BTN_ADD_TOOLTIP,
		iconCls:'icon-adds',
		handler: display_form_window
    });

    m_customer_gbtn_update=new Ext.Button({
	    text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: m_customer_confirm_update
	});

    m_customer_gbtn_delete=new Ext.Button({
	    text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: m_customer_confirm_delete
	});

    /*Context Menu Button */

	m_customer_cbtn_update=new Ext.menu.Item({
		text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: m_customer_editContextMenu
	});

	m_customer_cbtn_delete=new Ext.menu.Item({
		text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: m_customer_confirm_delete
	});

	/* Declare DataStore and  show datagrid list */
	m_customer_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 'm_customer_ListEditorGrid',
		el: 'fp_m_customer',
		title: TITLE_LIST,
		autoHeight: true,
		collapsible: true,
		store: m_customer_DataStore, // DataStore
		cm: m_customer_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
	  	width: 700,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: m_customer_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		m_customer_gbtn_add, '-',
		m_customer_gbtn_update, '-',
		m_customer_gbtn_delete, '-',
		{
			text: BTN_SEARCH_TITLE,
			tooltip: BTN_SEARCH_TOOLTIP,
			iconCls:'icon-search',
			handler: display_form_search_window
		}, '-',
		new Ext.app.SearchField({
			store: m_customer_DataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						m_customer_DataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
				Ext.get(this.id).set({qtitle: BTN_SIMPLE_SEARCH_TOOLTIP});
				}
			},
			width: 120
		}),'-',{
			text: BTN_REFRESH_TITLE,
			tooltip: BTN_REFERSH_TOOLTIP,
			handler: m_customer_reset_search,
			iconCls:'icon-refresh'
		},'-',{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: m_customer_export_excel
		}, '-',{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: m_customer_print
		}
		]
	});
	m_customer_ListEditorGrid.render();
	/* End of DataStore */

	/* Create Context Menu */
	m_customer_ContextMenu = new Ext.menu.Menu({
		id: 'm_customer_ContextMenu',
		items: [
		m_customer_cbtn_update,
		m_customer_cbtn_delete,
		'-',
		{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: m_customer_print
		},
		{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: m_customer_export_excel
		}
		]
	});
	/* End of Declaration */

	/* Event while selected row via context menu */
	function onm_customer_ContextMenu(grid, rowIndex, e) {
		e.stopEvent();
		var coords = e.getXY();
		m_customer_ContextMenu.rowRecord = grid.store.getAt(rowIndex);
		grid.selModel.selectRow(rowIndex);
		m_customer_SelectedRow=rowIndex;
		m_customer_ContextMenu.showAt([coords[0], coords[1]]);
  	}
  	/* End of Function */

	/* function for editing row via context menu */
	function m_customer_editContextMenu(){
		//m_customer_ListEditorGrid.startEditing(m_customer_SelectedRow,1);
		m_customer_confirm_update();
  	}
	/* End of Function */

	m_customer_ListEditorGrid.addListener('rowcontextmenu', onm_customer_ContextMenu);
	m_customer_DataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
	//m_customer_ListEditorGrid.on('afteredit', m_customer_inline_update); // inLine Editing Record

	customer_idField= new Ext.form.NumberField({
		id: 'customer_idField',
		fieldLabel: 'Customer Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
                hidden: true,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	customer_cpField= new Ext.form.TextField({
		id: 'customer_cpField',
		fieldLabel: 'Kontak ',
		maxLength: 25,
		anchor: '95%'
	});
	customer_hpField= new Ext.form.TextField({
		id: 'customer_hpField',
		fieldLabel: 'No HP ',
		maxLength: 20,
		anchor: '95%'
	});
	customer_nameField= new Ext.form.TextField({
		id: 'customer_nameField',
		fieldLabel: 'Perusahaan ',
		maxLength: 25,
		anchor: '95%'
	});
	customer_addressField= new Ext.form.TextArea({
		id: 'customer_addressField',
		fieldLabel: 'Alamat ',
		maxLength: 100,
		anchor: '95%'
	});
	customer_cityField= new Ext.form.TextField({
		id: 'customer_cityField',
		fieldLabel: 'Kota ',
		maxLength: 20,
		anchor: '95%'
	});
	customer_postField= new Ext.form.TextField({
		id: 'customer_postField',
		fieldLabel: 'Kode Pos ',
		maxLength: 6,
		anchor: '95%'
	});
	customer_phoneField= new Ext.form.TextField({
		id: 'customer_phoneField',
		fieldLabel: 'Telpon ',
		maxLength: 20,
		anchor: '95%'
	});
	customer_faxField= new Ext.form.TextField({
		id: 'customer_faxField',
		fieldLabel: 'Fax ',
		maxLength: 20,
		anchor: '95%'
	});
	customer_mailField= new Ext.form.TextField({
		id: 'customer_mailField',
		fieldLabel: 'eMail ',
		maxLength: 50,
		anchor: '95%'
	});


	m_customer_btn_Save=new Ext.Button({
		text: BTN_SAVE,
		handler: m_customer_save
	})
	/* Function for retrieve create Window Panel*/
	m_customer_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		title: TITLE_FORM+' M Customer',
		bodyStyle:'padding:5px',
		autoHeight:true,
		layout:'column',
		width: 500,
		collapsible: true,
		frame: true,
		renderTo: 'elwindow_m_customer_save',
		items:[
			{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [customer_cpField,
                                        customer_hpField,
                                        customer_nameField,
                                        customer_addressField,
                                        customer_cityField ] 
			},
                        {
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [customer_postField,
                                        customer_phoneField,
                                        customer_faxField,
                                        customer_mailField,new  Ext.form.Label({html:'Keterangan : <font color=red>*</font>  '+INFO_REQUIRED })] 
			}
			],
                    buttons: [m_customer_btn_Save
			,{
				text: BTN_CANCEL,
				handler: function(){
					m_customer_reset_form();
				}
			}
		]
	});
	/* End  of Function*/


	/* Function for action list search */
	function m_customer_list_search(){

		var customer_id_search=null;
		var customer_cp_search=null;
		var customer_hp_search=null;
		var customer_name_search=null;
		var customer_address_search=null;
		var customer_city_search=null;
		var customer_post_search=null;
		var customer_phone_search=null;
		var customer_fax_search=null;
		var customer_mail_search=null;

		if(customer_idSearchField.getValue()!==null){customer_id_search=customer_idSearchField.getValue();}
		if(customer_cpSearchField.getValue()!==null){customer_cp_search=customer_cpSearchField.getValue();}
		if(customer_hpSearchField.getValue()!==null){customer_hp_search=customer_hpSearchField.getValue();}
		if(customer_nameSearchField.getValue()!==null){customer_name_search=customer_nameSearchField.getValue();}
		if(customer_addressSearchField.getValue()!==null){customer_address_search=customer_addressSearchField.getValue();}
		if(customer_citySearchField.getValue()!==null){customer_city_search=customer_citySearchField.getValue();}
		if(customer_postSearchField.getValue()!==null){customer_post_search=customer_postSearchField.getValue();}
		if(customer_phoneSearchField.getValue()!==null){customer_phone_search=customer_phoneSearchField.getValue();}
		if(customer_faxSearchField.getValue()!==null){customer_fax_search=customer_faxSearchField.getValue();}
		if(customer_mailSearchField.getValue()!==null){customer_mail_search=customer_mailSearchField.getValue();}

		m_customer_DataStore.baseParams = {
			task: 'SEARCH',
			customer_id	:	customer_id_search,			customer_cp	:	customer_cp_search,			customer_hp	:	customer_hp_search,			customer_name	:	customer_name_search,			customer_address	:	customer_address_search,			customer_city	:	customer_city_search,			customer_post	:	customer_post_search,			customer_phone	:	customer_phone_search,			customer_fax	:	customer_fax_search,			customer_mail	:	customer_mail_search		};

		m_customer_DataStore.reload({params: {start: 0, limit: pageS}});
	}

	/* Function for reset search result */
	function m_customer_reset_search(){
		m_customer_DataStore.baseParams = { task: 'LIST' };
		m_customer_DataStore.reload({params: {start: 0, limit: pageS}});
		m_customer_searchWindow.close();
	};
	/* End of Fuction */

	/* Field for search */
	/* Identify  customer_id Search Field */
	customer_idSearchField= new Ext.form.NumberField({
		id: 'customer_idSearchField',
		fieldLabel: 'Customer Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
                hidden: true,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  customer_cp Search Field */
	customer_cpSearchField= new Ext.form.TextField({
		id: 'customer_cpSearchField',
		fieldLabel: 'Customer Cp',
		maxLength: 25,
		anchor: '95%'
	});
	/* Identify  customer_hp Search Field */
	customer_hpSearchField= new Ext.form.TextField({
		id: 'customer_hpSearchField',
		fieldLabel: 'Customer Hp',
		maxLength: 20,
		anchor: '95%'
	});
	/* Identify  customer_name Search Field */
	customer_nameSearchField= new Ext.form.TextField({
		id: 'customer_nameSearchField',
		fieldLabel: 'Customer Name',
		maxLength: 25,
		anchor: '95%'
	});
	/* Identify  customer_address Search Field */
	customer_addressSearchField= new Ext.form.TextField({
		id: 'customer_addressSearchField',
		fieldLabel: 'Customer Address',
		maxLength: 100,
		anchor: '95%'
	});
	/* Identify  customer_city Search Field */
	customer_citySearchField= new Ext.form.TextField({
		id: 'customer_citySearchField',
		fieldLabel: 'Customer City',
		maxLength: 20,
		anchor: '95%'
	});
	/* Identify  customer_post Search Field */
	customer_postSearchField= new Ext.form.TextField({
		id: 'customer_postSearchField',
		fieldLabel: 'Customer Post',
		maxLength: 6,
		anchor: '95%'
	});
	/* Identify  customer_phone Search Field */
	customer_phoneSearchField= new Ext.form.TextField({
		id: 'customer_phoneSearchField',
		fieldLabel: 'Customer Phone',
		maxLength: 20,
		anchor: '95%'
	});
	/* Identify  customer_fax Search Field */
	customer_faxSearchField= new Ext.form.TextField({
		id: 'customer_faxSearchField',
		fieldLabel: 'Customer Fax',
		maxLength: 20,
		anchor: '95%'
	});
	/* Identify  customer_mail Search Field */
	customer_mailSearchField= new Ext.form.TextField({
		id: 'customer_mailSearchField',
		fieldLabel: 'Customer Mail',
		maxLength: 50,
		anchor: '95%'
	});

	/* Function for retrieve search Form Panel */
	m_customer_searchForm = new Ext.FormPanel({
		labelAlign: 'left',
		layout:'form',
		bodyStyle:'padding:5px',
		autoHeight:true,
		frame: true,
		width: 500,
		items: [customer_idSearchField,
				customer_cpSearchField,
				customer_hpSearchField,
				customer_nameSearchField,
				customer_addressSearchField,
				customer_citySearchField,
				customer_postSearchField,
				customer_phoneSearchField,
				customer_faxSearchField,
				customer_mailSearchField
		 ],
		buttons: [{
				text: BTN_SEARCH,
				handler: m_customer_list_search
			},{
				text: BTN_CANCEL,
				handler: function(){
					m_customer_searchWindow.hide();
				}
			}
		]
	});
    /* End of Function */

	/* Function for retrieve search Window Form, used for andvaced search */
	m_customer_searchWindow = new Ext.Window({
		title: TITLE_FORM_SEARCH+'m_customer',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		plain:true,
		layout: 'fit',
		x: 0,
		y: 0,
		modal: true,
		renderTo: 'elwindow_m_customer_search',
		items: m_customer_searchForm
	});
    /* End of Function */

  	/* Function for Displaying  Search Window Form */
	function display_form_search_window(){
		if(!m_customer_searchWindow.isVisible()){
			m_customer_searchWindow.show();
		} else {
			m_customer_searchWindow.toFront();
		}
	}
  	/* End Function */

	/* Function for print List Grid */
	function m_customer_print(){
		var searchquery = "";
		var customer_id_print=null;
		var customer_cp_print=null;
		var customer_hp_print=null;
		var customer_name_print=null;
		var customer_address_print=null;
		var customer_city_print=null;
		var customer_post_print=null;
		var customer_phone_print=null;
		var customer_fax_print=null;
		var customer_mail_print=null;

		if(m_customer_DataStore.baseParams.query!==null){searchquery = m_customer_DataStore.baseParams.query;}
		if(m_customer_DataStore.baseParams.customer_id!==null){customer_id_print = m_customer_DataStore.baseParams.customer_id;}
		if(m_customer_DataStore.baseParams.customer_cp!==null){customer_cp_print = m_customer_DataStore.baseParams.customer_cp;}
		if(m_customer_DataStore.baseParams.customer_hp!==null){customer_hp_print = m_customer_DataStore.baseParams.customer_hp;}
		if(m_customer_DataStore.baseParams.customer_name!==null){customer_name_print = m_customer_DataStore.baseParams.customer_name;}
		if(m_customer_DataStore.baseParams.customer_address!==null){customer_address_print = m_customer_DataStore.baseParams.customer_address;}
		if(m_customer_DataStore.baseParams.customer_city!==null){customer_city_print = m_customer_DataStore.baseParams.customer_city;}
		if(m_customer_DataStore.baseParams.customer_post!==null){customer_post_print = m_customer_DataStore.baseParams.customer_post;}
		if(m_customer_DataStore.baseParams.customer_phone!==null){customer_phone_print = m_customer_DataStore.baseParams.customer_phone;}
		if(m_customer_DataStore.baseParams.customer_fax!==null){customer_fax_print = m_customer_DataStore.baseParams.customer_fax;}
		if(m_customer_DataStore.baseParams.customer_mail!==null){customer_mail_print = m_customer_DataStore.baseParams.customer_mail;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_m_customer&m=get_action',
		params: {
			task: "PRINT",
		  	query: searchquery,
			customer_id : customer_id_print,
			customer_cp : customer_cp_print,
			customer_hp : customer_hp_print,
			customer_name : customer_name_print,
			customer_address : customer_address_print,
			customer_city : customer_city_print,
			customer_post : customer_post_print,
			customer_phone : customer_phone_print,
			customer_fax : customer_fax_print,
			customer_mail : customer_mail_print,
		  	currentlisting: m_customer_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				window.open('./print/m_customer_printlist.html','m_customerlist','height=600,width=800,resizable=1,scrollbars=0, menubar=0');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_PRINT,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
		  	var result=response.responseText;
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	/* Enf Function */

	/* Function for print Export to Excel Grid */
	function m_customer_export_excel(){
		var searchquery = "";
		var customer_id_2excel=null;
		var customer_cp_2excel=null;
		var customer_hp_2excel=null;
		var customer_name_2excel=null;
		var customer_address_2excel=null;
		var customer_city_2excel=null;
		var customer_post_2excel=null;
		var customer_phone_2excel=null;
		var customer_fax_2excel=null;
		var customer_mail_2excel=null;

		if(m_customer_DataStore.baseParams.query!==null){searchquery = m_customer_DataStore.baseParams.query;}
		if(m_customer_DataStore.baseParams.customer_id!==null){customer_id_2excel = m_customer_DataStore.baseParams.customer_id;}
		if(m_customer_DataStore.baseParams.customer_cp!==null){customer_cp_2excel = m_customer_DataStore.baseParams.customer_cp;}
		if(m_customer_DataStore.baseParams.customer_hp!==null){customer_hp_2excel = m_customer_DataStore.baseParams.customer_hp;}
		if(m_customer_DataStore.baseParams.customer_name!==null){customer_name_2excel = m_customer_DataStore.baseParams.customer_name;}
		if(m_customer_DataStore.baseParams.customer_address!==null){customer_address_2excel = m_customer_DataStore.baseParams.customer_address;}
		if(m_customer_DataStore.baseParams.customer_city!==null){customer_city_2excel = m_customer_DataStore.baseParams.customer_city;}
		if(m_customer_DataStore.baseParams.customer_post!==null){customer_post_2excel = m_customer_DataStore.baseParams.customer_post;}
		if(m_customer_DataStore.baseParams.customer_phone!==null){customer_phone_2excel = m_customer_DataStore.baseParams.customer_phone;}
		if(m_customer_DataStore.baseParams.customer_fax!==null){customer_fax_2excel = m_customer_DataStore.baseParams.customer_fax;}
		if(m_customer_DataStore.baseParams.customer_mail!==null){customer_mail_2excel = m_customer_DataStore.baseParams.customer_mail;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_m_customer&m=get_action',
		params: {
			task: "EXCEL",
		  	query: searchquery,
			customer_id : customer_id_2excel,
			customer_cp : customer_cp_2excel,
			customer_hp : customer_hp_2excel,
			customer_name : customer_name_2excel,
			customer_address : customer_address_2excel,
			customer_city : customer_city_2excel,
			customer_post : customer_post_2excel,
			customer_phone : customer_phone_2excel,
			customer_fax : customer_fax_2excel,
			customer_mail : customer_mail_2excel,
		  	currentlisting: m_customer_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				win = window.location=('./export2excel.php');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_EXCEL,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
		  	var result=response.responseText;
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	/*End of Function */

	/* Show Hide control for permission */
	var pattr=new RegExp("R");
	var pattc=new RegExp("C");
	var pattu=new RegExp("U");
	var pattd=new RegExp("D");

	if(pattc.test(PERMISSION)==false){
		m_customer_gbtn_add.setVisible(false);
	}else{
		m_customer_gbtn_add.setVisible(true);
	}

	if(pattu.test(PERMISSION)==false){
		m_customer_gbtn_update.setVisible(false);
		m_customer_cbtn_update.setVisible(false);
	}else{
		m_customer_gbtn_update.setVisible(true);
		m_customer_cbtn_update.setVisible(true);
	}

	if(pattd.test(PERMISSION)==false){
		m_customer_gbtn_delete.setVisible(false);
		m_customer_cbtn_delete.setVisible(false);
	}else{
		m_customer_gbtn_delete.setVisible(true);
		m_customer_cbtn_delete.setVisible(true);
	}

	if(pattc.test(PERMISSION)==false && pattu.test(PERMISSION)==false){
		m_customer_btn_Save.setVisible(false);
	}else{
		m_customer_btn_Save.setVisible(true);
	}
});
	</script>
<body style: 'background: url(assets/images/desktop.jpg)'>
<div>
	<div class="col">
		<div id="elwindow_m_customer_save"></div>
		<div>&nbsp;</div>
		<div id="fp_m_customer"></div>
        <div id="elwindow_m_customer_search"></div>
    </div>
</div>
</body>
</html>